#include "primitive.h"
#include "intersection.h"

// Primitive Method Definitions
uint32_t Primitive::nextprimitiveId = 1;
Primitive::~Primitive() { }

bool Primitive::CanIntersect() const {
    return true;
}



GeometricPrimitive::GeometricPrimitive( Shape *s, Material *m) {
    shape = s;
    material = m;
}


BBox GeometricPrimitive::WorldBound() const{
    return shape->WorldBound();
}


bool GeometricPrimitive::CanIntersect() const {
    return shape->CanIntersect();
}



bool GeometricPrimitive::IntersectP(const Ray &r) const {
    return shape->IntersectP(r);
}


bool GeometricPrimitive::Intersect(const Ray &r,
                                   Intersection *isect) const {
    float thit, rayEpsilon;
    if (!shape->Intersect(r, &thit, &rayEpsilon, & isect->dg))
        return false;
    isect->primitive = this;
    isect->WorldToObject = *shape->WorldToObject;
    isect->ObjectToWorld = *shape->ObjectToWorld;
    isect->shapeId = shape->shapeId;
    isect->primitiveId = primitiveId;
    isect->rayEpsilon = rayEpsilon;
    r.maxt = thit;
    return true;
}

Material* GeometricPrimitive::getMaterial() const{
    return material;
}
